home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-06 | 50.0 KB | 1,700 lines | [TEXT/MPS ] |
- // Copyright © 1989-1990 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __UDEMODIALOGS__
- #include "UDemoDialogs.h"
- #endif
-
- extern "C" int strncmp (const char *s1, const char *s2, int n);
- extern "C" char* memcpy(void*, void*, int);
- #define pstrcpy(p,q) memcpy(p, q, q[0]+1) // added for translation: Pascal strcpy
-
- // Constants
- const short kNoOfLines = 10000;
- const short kMaxScrollBar = 1000;
- const short kTestIcon = 1000;
- const short kTestAlert = 1000;
- const short kTestPopup = 235;
- const short kBaudPopup = 236;
- const short kParityPopup = 237;
- const short kTestPicture = 1000;
- const short kTestStatic = 1000;
- const short kMaxPlaces = 13;
-
- // Constants for Command Items
- const short cFirstItem = 1001;
- const short cProcedureViews = 1001;
- const short cTemplateViews = 1002;
- const short cMonthlyDialog = 1003;
- const short cSaveDialog = 1004;
- const short cMarkDialog = 1005;
- const short cPageSetupDialog = 1006;
- const short cHomeBrewControls = 1007;
- const short cTabbingTest = 1008;
- const short cCalculator = 1009;
- const short cScrollingTest = 1011;
- const short cFormatDialog = 1012;
- const short cModelessMarkDialog = 1013;
- const short cLastItem = 1013;
- const short cPopupExample = 1100;
-
- const short mUpArrow = 100;
- const short mDownArrow = 101;
- const short mTemperatureChanged = 102;
-
-
- struct FondRecord {
- FamRec familyStuff;
- short noOfFonts;
- struct {
- short size;
- short style;
- short resID;
- } fontStuff[1000]; // not 1001!
- };
- typedef FondRecord *FondPointer, **FondHandle;
-
- static void MakeProcedureViews(CmdNumber aCmdNumber);
- static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp);
- static void MakeScrollingTest(CmdNumber aCmdNumber);
- static void MakeMonthlyDialog(CmdNumber aCmdNumber);
- static void MakeSaveDialog(CmdNumber aCmdNumber);
- static void MakeMarkDialog(CmdNumber aCmdNumber);
- static void MakeFormatDialog(CmdNumber aCmdNumber);
- static void MakePageSetupDialog(CmdNumber aCmdNumber);
- static void MakeHomeBrewControls(CmdNumber aCmdNumber);
- static void MakeTabTest(CmdNumber aCmdNumber);
- static void MakeCalculator(CmdNumber aCmdNumber);
- static void MakeModelessMarkDialog(CmdNumber aCmdNumber);
- //--------------------------------------------------------------------------------------------------
-
- const short kMonths = 12;
-
- long gMonthlyValues[kMonths];
- IDType gMonthIDs[kMonths];
-
- //********************************************************************************************
- // T T e s t A p p l i c a t i o n
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AInit
-
- pascal void
- TTestApplication::ITestApplication(OSType itsMainFileType)
- {
- Ptr monthIDs;
- TMonthlyDialog *aMonthlyDialog;
- TArrowsControl *anArrowsControl;
- TTemperatureCluster *aTemperatureCluster;
- TTemperatureConversionCluster *aTemperatureConversionCluster;
- THomeBrewDialog *anHomeBrewDialog;
- TSlider *aSlider;
- TPageSetupDialog *aPageSetupDialog;
- TRadioIcon *aRadioIcon;
- TSumStaticText *aSumStaticText;
- TCalcDialog *aCalcDialog;
- TNumbersView *aNumbersView;
- TFontListView *aFontListView;
- TSizeListView *aSizeListView;
- TModelessMarkDialog *aModelessMarkDialog;
- TScrollBar *aScrollBar;
- TGraph *aGraph;
-
- IApplication(itsMainFileType);
- fLaunchWithNewDocument = FALSE; // Suppress the creation of a new document at launch
-
- monthIDs = "jan feb mar apr may jun jul aug sep oct nov dec ";
- BlockMove(monthIDs, (Ptr) gMonthIDs, sizeof(gMonthIDs));
-
- for (short i = 0 ; i < kMonths ; i++) {
- gMonthlyValues[i] = (i+1) * 100;
- }
- if (gDeadStripSuppression) { // Hack so linker won't dead strip our custom view descendants
- aMonthlyDialog = new TMonthlyDialog;
- anArrowsControl = new TArrowsControl;
- aTemperatureCluster = new TTemperatureCluster;
- aTemperatureConversionCluster = new TTemperatureConversionCluster;
- aSlider = new TSlider;
- anHomeBrewDialog = new THomeBrewDialog;
- aFontListView = new TFontListView;
- aSizeListView = new TSizeListView;
- aRadioIcon = new TRadioIcon;
- aPageSetupDialog = new TPageSetupDialog;
- aSumStaticText = new TSumStaticText;
- aCalcDialog = new TCalcDialog;
- aNumbersView = new TNumbersView;
- aModelessMarkDialog = new TModelessMarkDialog;
- aScrollBar = new TScrollBar;
- aGraph = new TGraph;
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ASelCommand
-
- pascal TCommand *
- TTestApplication::DoMenuCommand(CmdNumber aCmdNumber)
- {
- TCommand *returnVal = NULL;
-
- switch (aCmdNumber) {
- case cProcedureViews:
- MakeProcedureViews(aCmdNumber);
- break;
- case cTemplateViews:
- MakeTemplateViews(aCmdNumber, this);
- break;
- case cScrollingTest:
- MakeScrollingTest(aCmdNumber);
- break;
- case cMonthlyDialog:
- MakeMonthlyDialog(aCmdNumber);
- break;
- case cSaveDialog:
- MakeSaveDialog(aCmdNumber);
- break;
- case cMarkDialog:
- MakeMarkDialog(aCmdNumber);
- break;
- case cModelessMarkDialog:
- MakeModelessMarkDialog(aCmdNumber);
- break;
- case cFormatDialog:
- MakeFormatDialog(aCmdNumber);
- break;
- case cPageSetupDialog:
- MakePageSetupDialog(aCmdNumber);
- break;
- case cHomeBrewControls:
- MakeHomeBrewControls(aCmdNumber);
- break;
- case cTabbingTest:
- MakeTabTest(aCmdNumber);
- break;
- case cCalculator:
- MakeCalculator(aCmdNumber);
- break;
- default:
- returnVal = inherited::DoMenuCommand(aCmdNumber);
- break;
- }
- return returnVal;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeProcedureViews(CmdNumber aCmdNumber)
- {
- RGBColor aColor;
- VPoint itsLocation;
- VPoint itsSize;
- TextStyle ts;
- TWindow *aWindow;
- TDialogView *aDialogView;
- TCluster *aCluster;
- TRadio *aRadio[8];
- TButton *aButton;
- TIcon *anIcon;
- TCheckBox *aCheckBox;
- TPopup *aPopup;
- TPicture *aPicture;
- TStaticText *aStaticText;
- TEditText *anEditText;
- Str255 s;
-
- aDialogView = new TDialogView;
- FailNIL(aDialogView);
- SetVPt(&itsSize, 480, 900);
- aDialogView->IDialogView(NULL, NULL, &gZeroVPt, &itsSize, sizeFixed,
- sizeFixed, kNoIdentifier, kNoIdentifier);
- aDialogView->ParamTxt("\p^0", "\pPARAM0");
- aDialogView->ParamTxt("\p^1", "\pPARAM1");
-
- aWindow = NewSimpleWindow(aCmdNumber, TRUE, TRUE, NULL, aDialogView);
- aWindow->fFreeOnClosing = TRUE;
- aWindow->fMustStagger = TRUE;
- aWindow->fMustForceOnScreen = TRUE;
- aWindow->SimpleStagger(kStdStaggerAmount, kStdStaggerAmount,
- &gStdStaggerCount);
-
- aStaticText = new TStaticText;
- FailNIL(aStaticText);
- SetVPt(&itsLocation, 50, 100);
- SetVPt(&itsSize, 300, 150);
- aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kTestStatic, 1);
- SetRGBColor(&aColor, 0, 0, 0xFFFF);
- SetTextStyle(&ts, applFont, italic, 12, &aColor);
- aStaticText->InstallTextStyle(&ts, kDontRedraw);
- aStaticText->SetJustification(teJustCenter, kRedraw);
-
- aCluster = new TCluster;
- FailNIL(aCluster);
- SetVPt(&itsLocation, 100, 340);
- SetVPt(&itsSize, 150, 190);
- aCluster->ICluster(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kNoResource, 0);
- aCluster->SetLabel("\pA Cluster!", kRedraw);
-
- SetVPt(&itsSize, 130, 20);
- for (short i = 0 ; i <= 7 ; i++) {
- aRadio[i] = new TRadio;
- FailNIL(aRadio[i]);
- SetVPt(&itsLocation, 10, (i + 1) * 20);
- aRadio[i]->IRadio(aCluster, &itsLocation, &itsSize, sizeVariable, sizeVariable, (StringPtr) "\p", i == 0);
- SetTextStyle(&ts, systemFont, Style((1 << i)/2), 12, &gRGBBlack);
- aRadio[i]->InstallTextStyle(&ts, kDontRedraw);
- switch (i) {
- case 0:
- aRadio[i]->SetText("\pPlain", kRedraw);
- break;
- case 1:
- aRadio[i]->SetText("\pBold", kRedraw);
- break;
- case 2:
- aRadio[i]->SetText("\pItalic", kRedraw);
- break;
- case 3:
- aRadio[i]->SetText("\pUnderline", kRedraw);
- break;
- case 4:
- aRadio[i]->SetText("\pOutline", kRedraw);
- break;
- case 5:
- aRadio[i]->SetText("\pShadow", kRedraw);
- break;
- case 6:
- aRadio[i]->SetText("\pCondense", kRedraw);
- break;
- case 7:
- aRadio[i]->SetText("\pExtend", kRedraw);
- break;
- }
- }
-
- aCheckBox = new TCheckBox;
- FailNIL(aCheckBox);
- SetVPt(&itsLocation, 100, 540);
- SetVPt(&itsSize, 100, 20);
- aCheckBox->ICheckBox(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
- "\pCheck Box", FALSE);
- SetTextStyle(&ts, applFont, NULL, 12, &gRGBBlack);
- aCheckBox->InstallTextStyle(&ts, kRedraw);
-
- aButton = new TButton;
- FailNIL(aButton);
- SetVPt(&itsLocation, 270, 540);
- SetVPt(&itsSize, 100, 28);
- aButton->IButton(aDialogView, &itsLocation, &itsSize, sizeVariable, sizeVariable,
- "\pPush Button");
- SetTextStyle(&ts, applFont, NULL, 10, &gRGBBlack);
- aButton->InstallTextStyle(&ts, kDontRedraw);
- aButton->fAdornment = adnRRect;
- SetPt(&aButton->fPenSize, 3, 3);
- aButton->Inset(4, 4, kRedraw);
-
- anIcon = new TIcon;
- FailNIL(anIcon);
- SetVPt(&itsLocation, 130, 570);
- SetVPt(&itsSize, 35, 35);
- anIcon->IIcon(aDialogView, &itsLocation, &itsSize, sizeFixed, sizeFixed,
- kTestIcon, kPreferColor);
- anIcon->fAdornment = kFrame | adnShadow;
- anIcon->ViewEnable(TRUE, kDontRedraw);
- anIcon->Inset(1, 1, kDontRedraw);
-
- if (gConfiguration.hasHierarchicalMenus) {
- aPopup = new TPopup;
- FailNIL(aPopup);
- SetVPt(&itsLocation, 290, 589);
- SetVPt(&itsSize, 120, 22);
- aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kTestPopup, 2, 50);
-
- aPopup = new TPopup;
- FailNIL(aPopup);
- SetVPt(&itsLocation, 290, 624);
- SetVPt(&itsSize, 120, 22);
- aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kBaudPopup, 1, 50);
-
- aPopup = new TPopup;
- FailNIL(aPopup);
- SetVPt(&itsLocation, 290, 659);
- SetVPt(&itsSize, 120, 22);
- aPopup->IPopup(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kParityPopup, 1, 50);
- }
-
- aPicture = new TPicture;
- FailNIL(aPicture);
- SetVPt(&itsLocation, 100, 660);
- SetVPt(&itsSize, 0x18C - 0xF0 + 16, 0x12C - 0x8F + 16);
- aPicture->IPicture(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kTestPicture);
- SetPt(&aPicture->fPenSize, 2, 2);
- aPicture->fAdornment = adnRRect | adnShadow;
- aPicture->ViewEnable(TRUE, kDontRedraw);
- aPicture->Inset(8, 8, kDontRedraw);
-
- aStaticText = new TStaticText;
- FailNIL(aStaticText);
- SetVPt(&itsLocation, 20, 620);
- SetVPt(&itsSize, 100, 20);
- aStaticText->IStaticText(aDialogView, &itsLocation, &itsSize, sizeVariable,
- sizeVariable, kTestStatic, 2);
- SetRGBColor(&aColor, 0xFFFF, 0, 0);
- aStaticText->InstallColor(&aColor, kRedraw);
-
- anEditText = new TEditText;
- FailNIL(anEditText);
- SetVPt(&itsLocation, 140, 620);
- SetVPt(&itsSize, 100, 22);
- anEditText->IEditText(aDialogView, &itsLocation, &itsSize, 255);
- SetTextStyle(&ts, applFont, 0, 12, &gRGBBlack);
- anEditText->InstallTextStyle(&ts, kDontRedraw);
- anEditText->SetJustification(teJustRight, kDontRedraw);
- anEditText->SetText("\pEditText", kRedraw);
-
- // aDialogView->DoSelectEditText(anEditText, TRUE);
- aWindow->Open();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeTemplateViews(CmdNumber aCmdNumber, TTestApplication *aTestApp)
- {
- TWindow *aWindow;
- TDialogView *aDialogView;
- TPopup *aPopup;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aDialogView = (TDialogView *) aWindow->FindSubView('DLOG');
- if (gConfiguration.hasHierarchicalMenus)
- aPopup = (TPopup *) (aTestApp->DoCreateViews(NULL, aDialogView, cPopupExample,
- &gZeroVPt));
- aDialogView->ParamTxt("\p^0", "\pPARAM0");
- aDialogView->ParamTxt("\p^1", "\pPARAM1");
- aWindow->Open();
- }
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeScrollingTest(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- Point minSize;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- SetPt(&minSize, 315, 260);
- aWindow->SetResizeLimits(minSize, *((Point *) &aWindow->fResizeLimits.bottom));
- aWindow->Open();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeMonthlyDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- TMonthlyDialog *aMonthlyDialog;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aMonthlyDialog = (TMonthlyDialog *) aWindow->FindSubView('DLOG');
- if (aMonthlyDialog != NULL)
- aMonthlyDialog->StuffValues();
- aWindow->Open();
- }
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeSaveDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- IDType dismisser;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
-
- #if qDebug
- if (dismisser == 'yes ')
- printf("The user said yes.\n");
- else if (dismisser == 'no ')
- printf("The user said no.\n");
- else if (dismisser == 'cncl')
- printf("The user cancelled the dialog.\n");
- else
- printf("I don't know how the user responded.\n");
- #endif qDebug
- aWindow->Close();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeMarkDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- IDType dismisser;
- Str255 theMark;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
-
- dismisser = ((TDialogView *) aWindow->FindSubView('DLOG'))->PoseModally();
- #if qDebug
- if (dismisser == 'ok ') {
- ((TEditText *) aWindow->FindSubView('mark'))->GetText((StringPtr) &theMark);
- if (theMark[0] == 0)
- printf("No mark specified.\n");
- else
- printf("The mark is ‘%P’.\n", &theMark);
- } else
- printf("The dialog was cancelled.\n");
- #endif
- aWindow->Close();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeModelessMarkDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aWindow->Open();
- }
-
- static void MakeFormatDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- TDialogView *theDialog;
- IDType dismisser;
- TSizeListView *theSizeListView;
- TFontListView *theFontListView;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- theDialog = (TDialogView *) aWindow->FindSubView('DLOG');
-
- theSizeListView = (TSizeListView *) theDialog->FindSubView('slst');
- theSizeListView->InitSizeList();
-
- theFontListView = (TFontListView *) theDialog->FindSubView('flst');
- theFontListView->InitFontList();
-
- dismisser = theDialog->PoseModally();
- #if qDebug
- if( dismisser != 'ok ')
- printf("The dialog was cancelled.\n");
- #endif
- aWindow->Close();
- }
-
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakePageSetupDialog(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- TPageSetupDialog *theDialog;
- IDType dismisser;
- VHSelect orientation;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- theDialog = (TPageSetupDialog *) aWindow->FindSubView('DLOG');
- theDialog->GetOrientation(&orientation);
- ((TRadioIcon *) theDialog->FindSubView('vert'))->HiliteState(orientation == v, kDontRedraw);
- ((TRadioIcon *) theDialog->FindSubView('horz'))->HiliteState(orientation == h, kDontRedraw);
-
- dismisser = theDialog->PoseModally();
- #if qDebug
- if (dismisser == 'ok ') {
- } else
- printf("The dialog was cancelled.\n");
- #endif
- aWindow->Close();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeHomeBrewControls(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aWindow->Open();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeTabTest(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aWindow->Open();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static void MakeCalculator(CmdNumber aCmdNumber)
- {
- TWindow *aWindow;
- TCalcDialog *aCalcDialog;
-
- aWindow = NewTemplateWindow(aCmdNumber, NULL);
- FailNIL(aWindow);
- aCalcDialog = (TCalcDialog *) aWindow->FindSubView('DLOG');
- aCalcDialog->ClearSum();
- aWindow->Open();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void TTestApplication::DoSetupMenus()
- {
- inherited::DoSetupMenus();
-
- for (short i = cFirstItem; i<=cLastItem; i++)
- Enable(i, TRUE);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TTestApplication::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTTestApplication", NULL, bClass, DoToField_StaticLink);
- TApplication::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T N u m b e r s V i e w
- //*******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TNumbersView::Draw(Rect *area)
- {
- VRect viewRect;
- long i, firstLine, lastLine;
- VPoint vPt;
- Point pt;
- Str255 s;
-
- QDToViewRect(area, &viewRect);
- viewRect.right = viewRect.right - 1;
- viewRect.bottom = viewRect.bottom - 1;
- firstLine = (viewRect.top / 16) + 1;
- lastLine = (viewRect.bottom / 16) + 1;
- SetPortTextStyle(&gSystemStyle);
- for (i = firstLine; i<=lastLine; i++) {
- SetVPt(&vPt, 0, i * 16);
- pt = ViewToQDPt(&vPt);
- MoveTo(pt.h, pt.v);
- NumToString(i, s);
- DrawString(s);
- }
-
- inherited::Draw(area);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TNumbersView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTNumbersView", NULL, bClass, DoToField_StaticLink);
- TView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T M o n t h l y D i a l o g
- //*******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AClose
-
- pascal void
- TMonthlyDialog::DismissDialog(IDType dismisser)
- {
- for (short i = 0; i < kMonths; i++)
- gMonthlyValues[i] = ((TNumberText *) FindSubView(gMonthIDs[i]))->GetValue();
-
- inherited::DismissDialog(dismisser);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal TCommand *
- TMonthlyDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *info)
- {
- /* If option-tab is pressed, deselect the current edit text and
- leave nothing selected. This is for test purposes only.
- It is not part of the Macintosh user interface. */
-
- if ((ch == chTab) && (info->theOptionKey)) {
- DoSelectEditText(NULL, FALSE);
- return (NULL);
- } else
- return (inherited::DoKeyCommand(ch, aKeyCode, info));
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal Boolean
- TMonthlyDialog::DeselectCurrentEditText(void)
- {
- TGraph *aGraph;
- TNumberText *theNumberText;
-
- aGraph = (TGraph *) FindSubView('graf');
- for (short which = 0; which < kMonths; which++) {
- if (fCurrentEditText->fIdentifier == gMonthIDs[which]) {
- theNumberText = (TNumberText *) FindSubView(gMonthIDs[which]);
- if (theNumberText)
- aGraph->SetPoint(which+1, theNumberText->GetValue());
- aGraph->ComputeBars(kRedraw);
- break;
- }
- }
-
- return inherited::DeselectCurrentEditText();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TMonthlyDialog::StuffValues()
- {
- TGraph *aGraph;
- TNumberText *aNumberText;
-
- aGraph = (TGraph *) FindSubView('graf');
- for (short i = 0; i < kMonths; i++) {
- aNumberText = (TNumberText *) FindSubView(gMonthIDs[i]);
- if (aNumberText)
- aNumberText->SetValue(gMonthlyValues[i], kDontRedraw);
- aGraph->SetPoint(i+1, gMonthlyValues[i]);
- }
- aGraph->ComputeBars(kDontRedraw);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TMonthlyDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTMonthlyDialog", NULL, bClass, DoToField_StaticLink);
- TDialogView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //**************************************************************************************************
- // T M o d e l e s s M a r k D i a l o g
- //**************************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TModelessMarkDialog::DoChoice (TView *origView, short itsChoice)
- {
- Str255 theMark;
-
- switch (itsChoice) {
- case mDefaultKey: // This handles when user presses the 'return' key
- case mCancelKey: // This handles when user presses the 'esc' key
- case mButtonHit: // This handles clicking in 'OK' or 'Cancel' buttons
- if (origView->fIdentifier == fDefaultItem) {
- ((TEditText *) FindSubView('mark'))->GetText((StringPtr) &theMark);
- ((TWindow *)GetWindow())->Close();
- #if qDebug
- printf("The mark is ‘%P’\n", &theMark);
- #endif
- } else if (origView->fIdentifier == fCancelItem)
- ((TWindow *)GetWindow())->Close();
- break;
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TModelessMarkDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTModelessMarkDialog", NULL, bClass, DoToField_StaticLink);
- TDialogView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T F o n t L i s t V i e w
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- short FondAfter(StringPtr fontName, short noOfFonds)
- // Find the FOND whose name follows fontName alphabetically, and return its id and name
- {
- Handle theFondResource;
- short lastID = 0;
- short thisID;
- ResType itsType;
- Boolean foundFOND = FALSE;
- Str255 lastName;
- Str255 thisName;
-
- pstrcpy((char *) lastName, "\p~~~~~~~~");
- for (short index = 1; index < noOfFonds; index++) {
- theFondResource = GetIndResource('FOND', index);
- GetResInfo(theFondResource, &thisID, &itsType, thisName);
- if ((CompareStrings((StringPtr) &thisName, fontName) == 1) && (CompareStrings((StringPtr) &thisName, (StringPtr) &lastName) == -1)) {
- lastID = thisID;
- pstrcpy(lastName, thisName);
- foundFOND = TRUE;
- }
- }
- if (foundFOND)
- pstrcpy(fontName, lastName);
- else // Skip duplicate FOND names
- pstrcpy(fontName, "\p");
-
- return lastID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void
- TFontListView::InitFontList()
- {
- FontListPtr pFondIDs;
- short noOfFonds;
- Str255 aString;
- short fondID;
-
- fFontList = (FontListPtr) NULL;
- noOfFonds = CountResources('FOND');
- if (noOfFonds > kMaxFonds)
- noOfFonds = kMaxFonds;
- pFondIDs = (FontListPtr) NewPermPtr(noOfFonds * sizeof(short)); // array of shorts
- FailNIL(pFondIDs);
-
- pstrcpy(aString, "\p ");
- for (short i = 0; i <= noOfFonds; i++) { // put each FOND's id in the list…
- fondID = FondAfter(aString, noOfFonds); // …in alphabetical order
- (*pFondIDs)[i] = fondID;
- if (Length(aString) == 0) { // finished early
- noOfFonds = i;
- break; // break from a for loop
- }
- }
-
- fFontList = pFondIDs;
- InsRowLast(noOfFonds, 16);
-
- SelectItem(1, kDontExtend, kHighlight, kSelect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AClose
-
- pascal void
- TFontListView::Free()
- {
- DisposeIfPtr(fFontList);
- fFontList = (FontListPtr) NULL;
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TFontListView::GetItemText(short anItem, StringPtr aString)
- {
- Handle theFondResource;
- short itsID;
- ResType itsType;
-
- itsID = (*fFontList)[anItem-1];
- theFondResource = GetResource('FOND', itsID);
- GetResInfo(theFondResource, &itsID, &itsType, aString);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TFontListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
- Boolean select)
- {
- TView *aView;
-
- inherited::SelectItem(anItem, extendSelection, highlight, select);
-
- if (select) {
- aView = ((TView *) GetWindow())->FindSubView('slst');
- FailNIL(aView);
- ((TSizeListView *) aView)->InstallFontFamily((*fFontList)[anItem-1]);
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TFontListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTFontListView", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfFontList", (Ptr) &fFontList, bPointer, DoToField_StaticLink);
- TTextListView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T S i z e L i s t V i e w
- //********************************************************************************************
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void TSizeListView::InitSizeList()
- {
- fSelection = 0;
- fSelectedSize = 9;
- fFondIndex = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TSizeListView::GetItemText(short anItem, StringPtr aString)
- {
- short noOfSizes;
- FondHandle theFond;
-
- theFond = (FondHandle) GetResource('FOND', fFondIndex);
- noOfSizes = 0;
- for (short i = 0; i <= theFond[0]->noOfFonts; i++) {
- if (theFond[0]->fontStuff[i].style == 0 )
- noOfSizes = noOfSizes + 1;
- if (noOfSizes == anItem ) {
- NumToString(theFond[0]->fontStuff[i].size, aString);
- return;
- }
- }
- pstrcpy(aString, "\p"); // set it to the empty string
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AOpen
-
- pascal void
- TSizeListView::InstallFontFamily(short theFondIndex)
- {
- FondHandle theFond;
- short noOfSizes;
- short sizeToSelect;
-
- theFond = (FondHandle) GetResource('FOND', theFondIndex);
- noOfSizes = 0;
- sizeToSelect = 0;
- for (short i = 0; i <= theFond[0]->noOfFonts; i++)
- if (theFond[0]->fontStuff[i].style == 0) {
- noOfSizes = noOfSizes + 1;
- if (theFond[0]->fontStuff[i].size == fSelectedSize)
- sizeToSelect = noOfSizes;
- }
- fFondIndex = theFondIndex;
- SetNumberOfItems(noOfSizes);
- SelectItem(sizeToSelect, kDontExtend, kDontHighlight, kSelect);
- ForceRedraw();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSizeListView::SelectItem(short anItem, Boolean extendSelection, Boolean highlight,
- Boolean select)
- {
- Str255 aString;
- TNumberText *theSizeView;
- long fontSize;
-
- inherited::SelectItem(anItem, extendSelection, highlight, select);
-
- if ( select && (anItem != 0) ) {
- GetItemText(anItem, aString);
- theSizeView = (TNumberText *) (((TView *) GetWindow())->FindSubView('size'));
- theSizeView->SetText((StringPtr) &aString, kRedraw);
- theSizeView->SetSelection(0, SHRT_MAX, kRedraw);
- StringToNum(aString, &fontSize);
- fSelectedSize = (short) fontSize;
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSizeListView::SetNumberOfItems(short aNumber)
- {
- SelectItem(0, kDontExtend, kHighlight, kSelect);
-
- if ( fNumOfRows > aNumber )
- DelItemFirst(fNumOfRows - aNumber);
- else if ( fNumOfRows < aNumber )
- InsItemFirst(aNumber - fNumOfRows);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TSizeListView::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTSizeListView", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfSelection", (Ptr) &fSelection, bInteger, DoToField_StaticLink);
- (*DoToField)("\pfSelectedSize", (Ptr) &fSelectedSize, bInteger, DoToField_StaticLink);
- (*DoToField)("\pfFondIndex", (Ptr) &fFondIndex, bInteger, DoToField_StaticLink);
- TTextListView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T P a g e S e t u p D i a l o g
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TPageSetupDialog::TPageSetupDialog()
- {
- fOrientation = v;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TPageSetupDialog::DoChoice(TView *origView, short itsChoice)
- {
-
- VHSelect newOrientation;
- TCheckBox *tallAdjCheckBox;
-
- switch (itsChoice) {
- case mIconHit:
- if (origView->fIdentifier == 'vert')
- newOrientation = v;
- else
- newOrientation = h;
- if (newOrientation != fOrientation) {
- ((TRadioIcon *) FindSubView('vert'))->HiliteState(newOrientation == v, kRedraw);
- ((TRadioIcon *) FindSubView('horz'))->HiliteState(newOrientation == h, kRedraw);
- tallAdjCheckBox = (TCheckBox *) FindSubView('tall');
- tallAdjCheckBox->DimState(newOrientation == h, kRedraw);
- tallAdjCheckBox->SetVal(0, kRedraw);
- fOrientation = newOrientation;
- }
- break;
-
- default:
- inherited::DoChoice(origView, itsChoice);
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TPageSetupDialog::GetOrientation(VHSelect *theOrientation)
- {
- *theOrientation = fOrientation;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TPageSetupDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTPageSetupDialog", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfOrientation", (Ptr) &fOrientation, bVHSelect, DoToField_StaticLink);
- TDialogView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T R a d i o I c o n
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- pascal void
- TRadioIcon::TrackMouse(TrackPhase aTrackPhase, VPoint *,
- VPoint *, VPoint *,
- Boolean )
- {
- if (aTrackPhase == trackPress)
- DoChoice(this, mIconHit);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TRadioIcon::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTRadioIcon", NULL, bClass, DoToField_StaticLink);
- TIcon::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T H o m e B r e w D i a l o g
- //********************************************************************************************
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal Boolean
- THomeBrewDialog::DoSetCursor(Point , RgnHandle )
- // localPoint & cursorRgn removed from declaration so CFront won't complain that it isn't used
- {
- CursHandle theCursor;
-
- theCursor = GetCursor(crossCursor);
- SetCursor(*theCursor);
- return TRUE;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal TView *
- THomeBrewDialog::HandleCursor(VPoint *theMouse, RgnHandle cursorRgn)
- {
- if (Focus() && DoSetCursor(ViewToQDPt(theMouse), cursorRgn))
- return this;
- else
- return (TView *) NULL;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- THomeBrewDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTHomeBrewDialog", NULL, bClass, DoToField_StaticLink);
- TDialogView::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T A r r o w s C o n t r o l
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void
- TArrowsControl::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
- {
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- fLastChange = 0;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AClose
-
- pascal void
- TArrowsControl::TrackMouse(TrackPhase aTrackPhase, VPoint *,
- VPoint *, VPoint *nextPoint,
- Boolean )
- // anchorPoint, previousPoint, & mouseDidMove removed from declaration so CFront won't
- // complain that they aren't used
- {
- if (TickCount() >= fLastChange + 5) {
- fLastChange = TickCount();
- if (aTrackPhase == trackPress)
- fLastChange = fLastChange + 10;
-
- if (ContainsMouse(nextPoint))
- if (nextPoint->v <= fSize.v / 2)
- DoChoice(this, mUpArrow);
- else
- DoChoice(this, mDownArrow);
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TArrowsControl::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTArrowsControl", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfLastChange", (Ptr) &fLastChange, bLongInt, DoToField_StaticLink);
- TPicture::Fields(DoToField, DoToField_StaticLink);
- }
-
- //******************************************************************************************
- // TTemperatureCluster
- //******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TTemperatureCluster::DoChoice(TView *, short itsChoice)
- // origView removed from declaration so CFront won't complain that it isn't used
- {
- TNumberText *theNumberText;
- long theNumber;
-
- switch (itsChoice) {
- case mUpArrow:
- case mDownArrow:
- theNumberText = (TNumberText *) FindSubView('Numb');
- theNumber = theNumberText->GetValue();
- if (itsChoice == mUpArrow)
- theNumber++;
- else
- theNumber--;
- theNumberText->SetValue(theNumber, kRedraw);
- // fall thru
- default:
- inherited::DoChoice(this,mTemperatureChanged);
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
-
- #pragma segment ARes
-
- pascal long
- TTemperatureCluster::GetValue()
- {
- TNumberText *numberText;
-
- numberText = (TNumberText *) FindSubView('Numb');
- return numberText->GetValue();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TTemperatureCluster::SetValue(long newValue, Boolean redraw)
- {
- TNumberText *numberText;
-
- numberText = (TNumberText *) FindSubView('Numb');
- numberText->SetValue(newValue,redraw);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TTemperatureCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTTemperatureCluster", NULL, bClass, DoToField_StaticLink);
- TCluster::Fields(DoToField, DoToField_StaticLink);
- }
-
- //******************************************************************************************
- // TTemperatureConversionCluster
- //******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TTemperatureConversionCluster::DoChoice(TView *origView, short itsChoice)
- {
- TTemperatureCluster *Celsius;
- TTemperatureCluster *Fahrenheit;
-
- if (itsChoice == mTemperatureChanged) {
- Celsius = (TTemperatureCluster *) FindSubView('Cels');
- FailNIL(Celsius);
- Fahrenheit = (TTemperatureCluster *) FindSubView('Fahr');
- FailNIL(Fahrenheit);
- if (origView == Celsius)
- Fahrenheit->SetValue(Celsius->GetValue()*1.8+32,kRedraw);
- else {
- if (origView == Fahrenheit)
- Celsius->SetValue((Fahrenheit->GetValue()-32)/1.8,kRedraw);
- }
- }
- else
- inherited::DoChoice(this,mTemperatureChanged);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TTemperatureConversionCluster::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTTemperatureConversionCluster", NULL, bClass, DoToField_StaticLink);
- TCluster::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T S l i d e r
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void
- TSlider::IRes(TDocument *, TView *itsSuperView, Ptr *itsParams)
- // itsDocument removed from declaration so CFront won't complain that it isn't used
- {
- PicHandle knobPicture;
- Rect knobRect;
- Rect *tmpR;
-
- inherited::IRes(NULL, itsSuperView, itsParams);
- knobPicture = GetPicture(1002);
- fKnobPicture = knobPicture;
-
- tmpR = &knobPicture[0]->picFrame;
- SetPt(((Point *) &knobRect.top), (short) fSize.h - (tmpR->right - tmpR->left), (short) fSize.v - 16);
- knobRect.right = knobRect.left + tmpR->right - tmpR->left;
- knobRect.bottom = knobRect.top + tmpR->bottom - tmpR->top;
-
- fMaxTop = knobRect.top;
- fMinTop = knobRect.top - 84;
- fKnobRect = knobRect;
- fValue = 0;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal Boolean
- TSlider::ContainsMouse(VPoint *theMouse)
- {
- Rect knobRect;
-
- GetKnobRect(&knobRect);
- return PtInRect(VPtToPt(theMouse), &knobRect);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSlider::Draw(Rect *area)
-
- {
- inherited::Draw(area); /* This draws everything but the knob */
- DrawKnob();
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSlider::DrawKnob()
- {
- Rect knobRect;
-
- GetKnobRect(&knobRect);
- LoadResource(Handle(fKnobPicture)); /* In case it was purged from memory */
- DrawPicture(fKnobPicture, &knobRect);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSlider::GetKnobRect(Rect *knobRect)
- {
- *knobRect = fKnobRect;
- OffsetRect(knobRect, 0, -(fValue * 12));
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TSlider::TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *previousPoint,
- VPoint *nextPoint, Boolean )
- // mouseDidMove removed from declaration so CFront won't complain that it isn't used
- {
- Rect oldRect;
- Rect newRect;
- Rect difference;
- RgnHandle savedClip;
- short base;
- short offset;
-
- GetKnobRect(&oldRect);
- newRect = oldRect;
-
- /* Compute rectangle of knob's current position */
- offset = (short) Min(Max(previousPoint->v - anchorPoint->v, fMinTop - newRect.top),
- fMaxTop - newRect.top);
- OffsetRect(&oldRect, 0, offset);
-
- /* Compute rectangle of knob's new position */
- offset = (short) Min(Max(nextPoint->v - anchorPoint->v, fMinTop - newRect.top),
- fMaxTop - newRect.top);
- OffsetRect(&newRect, 0, offset);
-
- /* If the mouse was release, pin the knob to a value and set slider's value */
- if (aTrackPhase == trackRelease) {
- base = (short) fSize.v - 16 - newRect.top;
- offset = base - ((base + 6) / 12 * 12);
- OffsetRect(&newRect, 0, offset);
- fValue = (short) ((fSize.v - 16 - newRect.top) / 12);
- }
-
- /* To redraw minimal amount, compute difference between old and new positions */
- difference = oldRect;
- if (oldRect.top > newRect.top)
- difference.top = (short) Max(oldRect.top, newRect.bottom);
- else
- difference.bottom = (short) Min(oldRect.bottom, newRect.top);
-
- savedClip = NewRgn();
- FailNIL(savedClip);
- GetClip(savedClip);
-
- ClipRect(&difference);
- inherited::Draw(&difference);
-
- SetClip(savedClip);
- DisposeRgn(savedClip);
- DrawPicture(fKnobPicture, &newRect);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TSlider::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTSlider", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfValue", (Ptr) &fValue, bInteger, DoToField_StaticLink);
- (*DoToField)("\pfKnobPicture", (Ptr) &fKnobPicture, bHandle, DoToField_StaticLink);
- (*DoToField)("\pfKnobRect", (Ptr) &fKnobRect, bRect, DoToField_StaticLink);
- (*DoToField)("\pfMinTop", (Ptr) &fMinTop, bInteger, DoToField_StaticLink);
- (*DoToField)("\pfMaxTop", (Ptr) &fMaxTop, bInteger, DoToField_StaticLink);
- TPicture::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T S u m S t a t i c T e x t
- //********************************************************************************************
- #pragma segment ARes
-
- pascal void
- TSumStaticText::Draw(Rect *area)
- {
- Rect theRect;
-
- /* Make sure the gray background gets completely erased */
- GetQDExtent(&theRect);
- InsetRect(&theRect, fPenSize.h, fPenSize.v);
- EraseRect(&theRect);
- inherited::Draw(area);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TSumStaticText::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTSumStaticText", NULL, bClass, DoToField_StaticLink);
- TStaticText::Fields(DoToField, DoToField_StaticLink);
- }
-
- //********************************************************************************************
- // T C a l c D i a l o g
- //********************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TCalcDialog::DoChoice(TView *origView, short itsChoice)
- {
- IDType origID;
-
- origID = origView->fIdentifier;
- switch (itsChoice) {
- case mOKHit: /*??? Should be mControlHit*/
- switch (origID & 0xFF) {
- case 'C':
- ClearSum();
- break;
- case '=':
- case 'E':
- TotalSum(noOperator);
- break;
- case '/':
- TotalSum(divOperator);
- break;
- case '*':
- TotalSum(mulOperator);
- break;
- case '-':
- TotalSum(subOperator);
- break;
- case '+':
- TotalSum(addOperator);
- break;
- default:
- NewDigit((short) origID & 0xFF);
- break;
- }
- break;
-
- default:
- inherited::DoChoice(origView, itsChoice);
- break;
- }
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal TCommand *
- TCalcDialog::DoKeyCommand(short ch, short aKeyCode, EventInfo *)
- // info removed from declaration so CFront won't complain that it isn't used
- {
- Boolean foundIt;
- long whoCares;
- IDType theID;
- TView *theView;
-
- foundIt = TRUE;
- if (aKeyCode == 0x47) /* Clear key */
- theID = 'keyC';
- else if ((ch == chEnter) || (ch == chReturn))
- theID = 'keyE';
- else
- switch (ch) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '.':
- case '+':
- case '-':
- case '*':
- case '/':
- case '=':
- theID = 'key ' | ch;
- break;
- default:
- foundIt = FALSE;
- SysBeep(1);
- break;
- }
-
- if (foundIt) {
- theView = FindSubView(theID);
- if (theView->Focus()) {
- ((TControl *) theView)->Hilite();
- Delay(5, &whoCares);
- ((TControl *) theView)->Hilite();
- }
- DoChoice(theView, mOKHit); /*??? mButtonHit? */
- }
- return NULL;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void TCalcDialog::ClearSum()
- {
- fArgument = 0.0;
- fSum = 0.0;
- fOperator = noOperator;
- fDecimalPoint = FALSE;
- fRestart = TRUE;
- ((TStaticText *) FindSubView('SUMM'))->SetText("\p0", kRedraw);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void TCalcDialog::FetchValue(long double *aValue)
- {
- Str255 theStr;
-
- ((TStaticText *) FindSubView('SUMM'))->GetText((StringPtr) theStr);
- p2cstr((StringPtr) theStr);
- sscanf((char *) theStr, "%Lf", aValue);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
-
- static pascal short POS(StringPtr subStr, StringPtr theStr)
- {
- short lSub = Length(subStr);
- short lStr = Length(theStr);
- char * p;
-
- if (theStr == NULL || subStr == NULL || (lSub > lStr)) return 0;
-
- p = (char *) &theStr[1];
- for (short index = 1; index <= 1 + (lStr - lSub); index++)
- {
- if (strncmp((char *) &subStr[1], p++, lSub))
- return index;
- }
- return 0;
- }
-
- static pascal void Truncate(StringPtr theStr)
- {
- char theChar;
-
- if (Length(theStr) > 1) {
- theChar = theStr[Length(theStr)];
- if ( (theChar == '0') || (theChar == '.') )
- theStr[0] -= 1;
- if ( theChar == '0' )
- Truncate(theStr);
- }
- }
-
- pascal void TCalcDialog::SetValue()
- {
- short thePos = 0;
- Str255 theStr;
- long double aExtended;
- int *decpt = NULL;
- int *sign = NULL;
-
- aExtended = fSum;
- sprintf((char *) theStr, "%Lf", aExtended);
- c2pstr((char *) theStr);
- thePos = POS("\p.", theStr);
- if (thePos != 0)
- Truncate(theStr);
- if ((thePos > kMaxPlaces) ||
- ((thePos != 0) && (POS("\p000000", theStr) == thePos + 1))) {
- aExtended = fSum;
- sprintf((char *) theStr, "%.2g", aExtended);
- c2pstr((char *) theStr);
- }
- if (Length(theStr) > kMaxPlaces)
- theStr[0] = kMaxPlaces;
-
- ((TStaticText *) FindSubView('SUMM'))->SetText((StringPtr) &theStr, kRedraw);
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- pascal void
- TCalcDialog::TotalSum(CalcOperator newOperator)
- {
- long double aValue;
-
- FetchValue(&aValue);
- fArgument = aValue;
- switch (fOperator) {
- case noOperator:
- fSum = fArgument;
- break;
- case divOperator:
- fSum = fSum / fArgument;
- break;
- case mulOperator:
- fSum = fSum * fArgument;
- break;
- case subOperator:
- fSum = fSum - fArgument;
- break;
- case addOperator:
- fSum = fSum + fArgument;
- break;
- }
- SetValue();
- fRestart = TRUE;
- fArgument = fSum;
- fOperator = newOperator;
- }
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment ARes
-
- static void SetIt(TStaticText *theText, StringPtr theStr, short theNumber)
- {
- theStr[Length(theStr) + 1] = theNumber;
- theStr[0] += 1;
- theText->SetText(theStr, kRedraw);
- }
-
- pascal void
- TCalcDialog::NewDigit(short theNumber)
- {
- TStaticText *theText;
- Str255 theStr;
-
- theText = (TStaticText *) FindSubView('SUMM');
- if (fRestart)
- pstrcpy(theStr, "\p");
- else
- theText->GetText((StringPtr) &theStr);
-
- if (Length(theStr) < kMaxPlaces) {
- fRestart = FALSE;
- if ((theNumber == '.') && !fDecimalPoint)
- fDecimalPoint = TRUE;
- SetIt(theText, theStr, theNumber);
- }
- }
-
-
- /*--------------------------------------------------------------------------------------------------*/
- #pragma segment AFields
-
- pascal void
- TCalcDialog::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTCalcDialog", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfSum", (Ptr) &fSum, bExtended, DoToField_StaticLink);
- (*DoToField)("\pfArgument", (Ptr) &fArgument, bExtended, DoToField_StaticLink);
- (*DoToField)("\pfOperator", (Ptr) &fOperator, bInteger, DoToField_StaticLink);
- (*DoToField)("\pfDecimalPoint", (Ptr) &fDecimalPoint, bBoolean, DoToField_StaticLink);
- (*DoToField)("\pfRestart", (Ptr) &fRestart, bBoolean, DoToField_StaticLink);
- TPicture::Fields(DoToField, DoToField_StaticLink);
- }
-